﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace Caviar.SharedKernel.Entities.IM
{
    [Index(nameof(UserName), IsUnique = true)]
    [Index(nameof(ClientId), IsUnique = true)]
    public class User : SysUseEntity
    {

        /// <summary>
        /// 昵称
        /// </summary>
        [StringLength(16, ErrorMessage = "LengthErrorMsg")]
        public string NickName { get; set; }

        /// <summary>
        /// 用户名
        /// </summary>
        [Required(ErrorMessage = "RequiredErrorMsg")]
        [StringLength(16, ErrorMessage = "LengthErrorMsg")]
        public string UserName { get; set; }

        /// <summary>
        /// 密码
        /// </summary>
        [Required(ErrorMessage = "RequiredErrorMsg")]
        [StringLength(32, ErrorMessage = "LengthErrorMsg")]
        public string Password { get; set; }

        /// <summary>
        /// 姓名
        /// </summary>
        [StringLength(100, ErrorMessage = "LengthErrorMsg")]
        public string Name { get; set; }

        /// <summary>
        /// 邮箱
        /// </summary>
        [StringLength(50, ErrorMessage = "LengthErrorMsg")]
        public string Email { get; set; }

        /// <summary>
        /// 生日
        /// </summary>
        [Required(ErrorMessage = "RequiredErrorMsg")]
        public DateTime Birthday { get; set; }

        /// <summary>
        /// 性别
        /// </summary>
        [Required(ErrorMessage = "RequiredErrorMsg")]
        public byte Sex { get; set; }

        /// <summary>
        /// 简介
        /// </summary>
        [StringLength(144, ErrorMessage = "LengthErrorMsg")]
        public string Profile { get; set; }

        /// <summary>
        /// 头像
        /// </summary>
        public string Avatar { get; set; }

        /// <summary>
        /// 个性签名
        /// </summary>
        [StringLength(256, ErrorMessage = "LengthErrorMsg")]
        public string Signature { get; set; }

        /// <summary>
        /// 电话
        /// </summary>
        [StringLength(20, ErrorMessage = "LengthErrorMsg")]
        public string Telephone { get; set; }

        /// <summary>
        /// 爱好
        /// </summary>
        [StringLength(256, ErrorMessage = "LengthErrorMsg")]
        public string Hobby { get; set; }

        /// <summary>
        /// 职业
        /// </summary>
        [StringLength(256, ErrorMessage = "LengthErrorMsg")]
        public string Vocation { get; set; }

        public bool IsActive { get; set; } = false;

        /// <summary>
        /// 客户端ID
        /// </summary>
        [Required(ErrorMessage = "RequiredErrorMsg")]
        [StringLength(36, ErrorMessage = "LengthErrorMsg")]
        public string ClientId { get; set; }

        /// <summary>
        /// Token
        /// </summary>
        public string Token { get; set; }

        /// <summary>
        /// 登录时间
        /// </summary>
        public DateTime? LoginTime { get; set; }

        ///// <summary>
        ///// 登录IP
        ///// </summary>
        //[StringLength(16, ErrorMessage = "LengthErrorMsg")]
        //public string LoginIP { get; set; }

        /// <summary>
        /// 上次登录时间
        /// </summary>
        public DateTime? LastLoginTime { get; set; }

        /// <summary>
        /// 上次离线时间
        /// </summary>
        public DateTime? LastOffline { get; set; }

        /// <summary>
        /// 是否在线
        /// </summary>
        public bool IsOnline { get; set; }

        /// <summary>
        /// 用户主题
        /// </summary>
        public ICollection<UserTopic> Topics { get; set; }
    }
}
